package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Reference
    private PermissionService permissionService;
    @RequestMapping("/findAll")
    //查询所有权限信息
    public Result findAll(){
        try{
            List<Permission> data =  permissionService.findAll();
            return new Result(true, MessageConstant.QUERY_PERMISSION_SUCCESS,data);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_PERMISSION_FAIL);
        }
    }

    @RequestMapping("/findPermissionIdsByRoleId")
    //根据角色id查询对应的权限id
    public Result findPermissionIdsByRoleId(Integer roleId){
        try {
            List<Integer> list = permissionService.findPermissionIdsByRoleId(roleId);
            return new Result(true,MessageConstant.QUERY_PERMISSION_SUCCESS,list);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_PERMISSION_FAIL);
        }

    }
}
